# -----------------------------------------------
# Author: yuz
# Copyright: 湖南零檬信息技术有限公司
# Email: wagyu2016@163.com
# Phone&Wechat: 18173179913
# Site: http://www.lemonban.com
# Forum: http://testingpai.com
# -----------------------------------------------
import base64
import json
import uuid

import requests

import config


def get_img():
    """获取验证码"""
    url = 'http://mall.lemonban.com:8108' + '/captcha.jpg'
    resp = requests.get(url, params={"uuid": uuid.uuid4()})
    return resp.content


def base64_api(uname, pwd, img, typeid):
    """上传图片"""
    base64_data = base64.b64encode(img)
    b64 = base64_data.decode()
    data = {"username": uname, "password": pwd, "typeid": typeid, "image": b64}
    result = json.loads(requests.post("http://api.ttshitu.com/predict", json=data).text)
    if result['success']:
        return result["data"]["result"]
    else:
        return result["message"]
    return ""


if __name__ == '__main__':
    img = get_img()
    result = base64_api('simple', 'yuan5311645', img, typeid=3)
    print(result)
